package com.xcm.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xcm.dao.ProgramBottomMapper;
import com.xcm.model.TbProgramBottom;
import com.xcm.service.ProgramBottomService;

/**
 * 下屏节目实现类
 */
@Service(value = "programBottomService")
public class ProgramBottomServiceImpl implements ProgramBottomService {

	@Autowired
	private ProgramBottomMapper programBottomMapper;

	/**
	 * 通过xc版本查找下屏节目列表
	 * @param xcVersion xc版本
	 * @param bottom 下屏节目
	 * @return  List<TbProgramBottom>
	 */
	@Override
	public List<TbProgramBottom> listProgramBottomByXcVersion(String xcVersion, String bottom) {
		bottom = bottom.replaceAll("\"","");  
		String [] bottoms = bottom.split(",");
		List<TbProgramBottom> orders = new ArrayList<>();
		List<TbProgramBottom> listProgramBottomByXcVersion = programBottomMapper.listProgramBottomByXcVersion(xcVersion, Arrays.asList(bottoms));
		
		// 不去重排序
		TbProgramBottom pro = null;
		for ( String str : bottoms ) {
			for (TbProgramBottom tbProg: listProgramBottomByXcVersion) {
				if ( str.equals(tbProg.getName()) ) {
					pro = tbProg;
					continue;
				}
			}
			orders.add(pro);
		}
		return orders;
	}
}
